package vsm.vsm_server.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vsm.vsm_server.pojo.Result.Result;
import vsm.vsm_server.pojo.User.Record.Like.LikeVideo;
import vsm.vsm_server.service.ActionService;
import vsm.vsm_server.service.LikeService;
import vsm.vsm_server.service.VideoService;

@Slf4j
@RestController
@RequestMapping("/like")
@CrossOrigin
public class LikeController {
    @Autowired
    private LikeService likeService;
    @Autowired
    private VideoService videoService;

    @PostMapping("/isLikeVideo")
    public Result<Boolean> isLikeVideo(@RequestBody LikeVideo likeVideo){
        Boolean islike = likeService.isLikeVideo(likeVideo);
        return Result.success(islike);
    }

    @PostMapping("/likeVideo")
    public Result<String> likeVideo(@RequestBody LikeVideo likeVideo){
        likeService.likeVideo(likeVideo);
        videoService.addLikeCount(likeVideo.getVideoId());
        return Result.success();
    }

    @PostMapping("/unlikeVideo")
    public Result<String> unlikeVideo(@RequestBody LikeVideo likeVideo){
        likeService.unlikeVideo(likeVideo);
        videoService.deLikeCount(likeVideo.getVideoId());
        return Result.success();
    }
}
